file system model: Add batched insertion
authorMatthias Clasen <mclasen@redhat.com>
Thu, 18 Jun 2015 16:19:06 +0000 (12:19 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 18 Jun 2015 17:11:30 +0000 (13:11 -0400)
Add a batched version of gtk_file_system_model_add_and_query_file
that takes a list of files and avoids resorting the model for each
individual insertion. The querying is still done one-file-at-a-time,
so more optimization is certainly possible.

gtk/gtkfilesystemmodel.c
gtk/gtkfilesystemmodel.h

index a92be1f5b1d0da4ac0fedbe11d25026488aeeaf6..096836bb64381d34be49fae00d7273ae91c1104d 100644 (file)
@@ -2129,3 +2129,39 @@ _gtk_file_system_model_add_and_query_file (GtkFileSystemModel *model,
                            gtk_file_system_model_query_done,
                            model);
 }
+
+static void
+gtk_file_system_model_one_query_done (GObject *     object,
+                                      GAsyncResult *res,
+                                      gpointer      data)
+{
+  GtkFileSystemModel *model = data; /* only a valid pointer if not cancelled */
+
+  gtk_file_system_model_query_done (object, res, data);
+  thaw_updates (model);
+}
+
+void
+_gtk_file_system_model_add_and_query_files (GtkFileSystemModel *model,
+                                            GList              *list,
+                                            const char         *attributes)
+{
+  GList *l;
+  GFile *file;
+
+  g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
+  g_return_if_fail (attributes != NULL);
+
+  for (l = list; l; l = l->next)
+    {
+      file = (GFile *)l->data;
+      freeze_updates (model);
+      g_file_query_info_async (file,
+                               attributes,
+                               G_FILE_QUERY_INFO_NONE,
+                               IO_PRIORITY,
+                               model->cancellable,
+                               gtk_file_system_model_one_query_done,
+                               model);
+    }
+}
index 6c6a051aacc0a84d37d8c4be7b5f37ba053a606a..5a2c8b1eb3ea959e35d787e1cda1d9b55b27fcad 100644 (file)
@@ -66,9 +66,12 @@ const GValue *      _gtk_file_system_model_get_value        (GtkFileSystemModel
                                                              GtkTreeIter *       iter,
                                                              int                 column);
 
-void                _gtk_file_system_model_add_and_query_file (GtkFileSystemModel *model,
-                                                             GFile              *file,
-                                                             const char         *attributes);
+void                _gtk_file_system_model_add_and_query_file  (GtkFileSystemModel *model,
+                                                                GFile              *file,
+                                                                const char         *attributes);
+void                _gtk_file_system_model_add_and_query_files (GtkFileSystemModel *model,
+                                                                GList              *files,
+                                                                const char         *attributes);
 void                _gtk_file_system_model_update_file      (GtkFileSystemModel *model,
                                                              GFile              *file,
                                                              GFileInfo          *info);